package com.qiyu.tech.shutdown.starter.conf;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;

/**
 * @Author idea
 * @Date created in 5:49 下午 2020/9/14
 */
@Slf4j
@Configurable
public class GracefulShutdownConfig {

    @Resource
    private GracefulShutdown gracefulShutdown;

    @Bean
    public ServletWebServerFactory serverFactory(){
        TomcatServletWebServerFactory tomcatServletWebServerFactory = new TomcatServletWebServerFactory();
        tomcatServletWebServerFactory.addConnectorCustomizers(gracefulShutdown);
        log.info("================ init GracefulShutdownConfig ================");
        return tomcatServletWebServerFactory;
    }
}
